package org.computate.tool;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.apache.commons.io.output.XmlStreamWriter;

public class FilesToXml {
	public static void main(String[] args) {
		if(args.length >= 1) {
			try {
				String projectPath = args[0];
				File projectDir = new File(projectPath);
				File outputXml = new File(projectDir, "xml/pageItems.xml.temp");
				XmlStreamWriter w = new XmlStreamWriter(outputXml);
				File modelDir = new File(projectDir, "src/main/java/org/computate/model/item");
				File formDir = new File(projectDir, "src/main/java/org/computate/form");
				
				w.write("<root>\n");
				for(File file : modelDir.listFiles()) {
					if(file.isFile()) {
						w.write("<model>" + file.getName().substring(0, file.getName().indexOf(".")) + "</model>\n");
					}
				}
				for(File file : formDir.listFiles()) {
					if(file.isFile()) {
						w.write("<form>" + file.getName().substring(0, file.getName().indexOf(".")) + "</form>\n");
					}
				}
				w.write("</root>\n");
				w.flush();
				w.close();
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
